/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.guilayer.sprites;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Massimo Canonaco
 *
 */
public class UniqueSpriteSheet implements SpriteSheetInterface
{
	/** */
	private Map<String,Sprite> sprites;
	
	/** */
	private BufferedImage image;
	
	public UniqueSpriteSheet()
	{
		sprites = new HashMap<String, Sprite>();
	}
	
	/** */
	public Image getFrame(String frameID) 
	{
		Sprite sprite = sprites.get(frameID);
//		System.out.println("richiesto "+frameID+" ... "+sprite.getFrameName());
		if(sprite != null)
		{
			return image.getSubimage(sprite.getTopX(), sprite.getTopY(), sprite.getWidth(), sprite.getHeight());
		}
		else
			return null;
	}

	/** */
	public Image getFrame(int topx, int topy, int width, int height) 
	{
		return image.getSubimage(topx, topy, width, height);
	}

	/** */
	public Sprite getNext(String frameID) 
	{
		Sprite sprite = sprites.get(frameID);
		if(sprite != null)
		{
			return sprite.getNext();
		}
		return null;
	}

	/** */
	public void setImage(Image image) 
	{
		if(image instanceof BufferedImage)
			this.image = (BufferedImage) image;
	}

	/** */
	public void addFrame(Sprite sprite) 
	{
//		System.out.println("Aggiungo il frame: "+sprite.getFrameName());
//		System.out.println(sprite);
		sprites.put(sprite.getFrameName(), sprite);
//		System.out.println("!!!!!!!");
//		System.out.println(sprite.getFrameName());
//		System.out.println("Lung sprites : "+sprites.size());
	}

	@Override
	public Sprite getSprite(String spriteID) 
	{
		return sprites.get(spriteID);
	}

//	/** */
//	public Map getSprites() 
//	{
//		return sprites;
//	}

}
